{% extends 'mysite/base.html' %}
{% load staticfiles %}
{% block content %}
    <script type="text/javascript">
        function digg(post_id, evaluate) {
            var gooddivHtml = $('#gooddiv').html();
            var baddivHtml = $('#baddiv').html();
            $('#gooddiv').html("<img src='/static/img/spinner.gif'/>");
            $('#baddiv').html("<img src='/static/img/spinner.gif'/>");
            $.ajax({
                url: "/post/" + post_id + "/" + evaluate + "/evaluate",
                type: "get",
                //data: {},
                datatype: "json",
                success: function (data) {
                    var gstr = '<strong>' + data['good'] + '</strong><br/>顶';
                    var bstr = '<strong>' + data['bad'] + '</strong><br/>踩';
                    $('#gooddiv').empty().addClass("digged").html(gstr);
                    $('#baddiv').empty().addClass("digged").html(bstr);
                    $("#digg_bottom").find("a").contents().unwrap();
                },
                error: function (data) {
                    alert("error: " + data);
                }
            });
        }
    </script>
    <div class="post">
        <h2>{{ post.title }}</h2>

        <div class="info">
            {% if post.published_date %}
                <span class="date">{{ post.published_date|date:'Y年m月d日' }}</span>
            {% else %}
                {% if user.is_authenticated %}
                    <a class="btn btn-default" href="{% url 'blog.views.post_publish' pk=post.pk %}"
                       onclick="return confirm('确定发布文章吗？');">发布</a>
                {% endif %}
            {% endif %}
            {% if post.published_date %}
            <span class="comments">
                {% if comments %}
                    {{ comments|length }} 条评论
                {% else %}
                    没有评论
                {% endif %}
            </span>
            <span class="comments"> {{ post.click }} 人阅读&nbsp;&nbsp;</span>
            {% endif %}
            {% if user.is_authenticated %}
                <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}">
                    <span class="glyphicon glyphicon-pencil"></span>
                </a>
                <a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"
                   onclick="return confirm('确定删除文章吗？');">
                    <span class="glyphicon glyphicon-remove"></span>
                </a>
            {% endif %}
            <div class="fixed"></div>
        </div>
        <div class="content">
            <p>
                {% autoescape off %}
                    {{ post.text }}
                {% endautoescape %}
            </p>
        </div>
        <div class="under">
            <span class="categories">分类: </span>
            <span>
                <a href="{% url 'blog.views.post_list_by_category' cg=post.category.name %}"
                   rel="category tag">{{ post.category.name }}
                </a>
            </span>
            <span class="tags">标签: </span>
            <span>
                {% for tg in post.tags.all %}
                    <a href="{% url 'blog.views.post_list_by_tag' tag=tg.name %}"
                       rel="tag">{{ tg.name }}</a>&nbsp;
                {% endfor %}
            </span>
        </div>
    </div>
    {% if post.published_date %}
        <div id="digg_bottom">
            {% if post.ip_count %}
                <div id="gooddiv" class="digged">
                    <strong id="good">{{ post.good }}</strong> <br>顶
                </div>
                <div id="baddiv" class="digged">
                    <strong id="bad">{{ post.bad }}</strong> <br>踩
                </div>
            {% else %}
                <a href="#" onclick="digg({{ post.id }}, 1);return false;">
                    <div id="gooddiv" {% if post.ip_count %} class="digged"{% endif %}>
                        <strong id="good">{{ post.good }}</strong> <br>顶
                    </div>
                </a>
                <a href="#" onclick="digg({{ post.id }}, 0);return false;">
                    <div id="baddiv" {% if post.ip_count %} class="digged"{% endif %}>
                        <strong id="bad">{{ post.bad }}</strong> <br>踩
                    </div>
                </a>
            {% endif %}
        </div>
    {% endif %}

    <div id="commentlist">
        {% if not comments %}
            <ol id="thecomments">
                <li class="messagebox">本文目前尚无任何评论.</li>
            </ol>
        {% else %}
            <ol id="thecomments">
                {% for comment in comments %}
                    <li class="comment regularcomment">
                        <div class="author">
                            <div class="pic">
                                <img src="http://yidaospace.qiniudn.com/avatar/9655bd49005892529ea4fafd625aaaf3?s=32&amp;d=&amp;r=G"
                                     class="avatar avatar-32 photo" height="32" width="32">
                            </div>
                            <div class="name">{{ comment.author }}</div>
                        </div>
                        <div class="info">
                            <div class="date">{{ comment.author|date:'Y年m月d日H:M' }}</div>
                            <div class="act"></div>
                            <div class="fixed"></div>
                            <div class="content">
                                <div id="commentbody-3">
                                    <p>{{ comment.text|truncatechars:100|linebreaks }}</p>
                                </div>
                            </div>
                        </div>
                        <div class="fixed"></div>
                    </li>
                {% endfor %}
            </ol>
        {% endif %}
        <!-- comments END -->
        <div class="fixed"></div>
    </div>
    <form action="{% url 'blog.views.add_comment' pk=post.pk %}" method="POST" id="commentform">
        {% csrf_token %}
        <div id="respond">
            <div id="author_info">
                <div class="row" style="margin-left:0">
                    <input type="text" name="author" id="author" class="textfield"
                           value="" size="24" tabindex="1">
                    <label for="author" class="small">昵称 (必填)</label>
                </div>
                <div class="row" style="margin-left:0">
                    <input type="text" name="email" id="email" class="textfield"
                           value="" size="24" tabindex="2">
                    <label for="email" class="small">电子邮箱 (我们会为您保密) (必填)</label>
                </div>
                <div class="row" style="margin-left:0">
                    <input type="text" name="" id="url" class="textfield"
                           value="" size="24" tabindex="3">
                    <label for="url" class="small">网址</label>
                </div>
            </div>
            <!-- comment input -->
            <div class="row" style="margin-left:-7px;">
                <label for="comment"></label>
                <textarea name="text" id="comment" tabindex="4" rows="8" cols="50"></textarea>
            </div>
            <!-- comment submit and rss -->
            <div id="submitbox">
                <div class="submitbutton">
                    <input name="submit" type="submit" id="submit" class="button" tabindex="5"
                           value="提交评论">
                </div>
                <div class="fixed"></div>
            </div>
        </div>
    </form>
    <div id="postnavi">
        {#        <span class="prev"><a href="#" rel="next"></a></span>#}
        {#		<span class="next"><a href="#" rel="prev"></a></span>#}
        <span class=""><a href="#" rel=""></a></span>
        <span class=""><a href="#" rel=""></a></span>

        <div class="fixed"></div>
    </div>
{% endblock %}
